<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/resouse/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/resouse/bootstrap-4.5.0/js/bootstrap.js"></script>
<link href="/resouse/bootstrap-4.5.0/css/bootstrap.css" rel="stylesheet">
</head>
<script type="text/javascript">
	function page(pageNum) {
		$("[name='pageNum']").val(pageNum);
		$("form").submit();
	}
	function query(queryType) {
		location = "list?queryType="+queryType;
	}
	function toAdd() {
		location = "toAdd";
	}
	function update(id) {
		location = "toUpdate?id="+id;
	}
	function del(id) {
		if(confirm("确定要删除"+id+"号数据吗?")){
			$.post(
				"del",
				{id:id},
				function(json) {
					if(json){
						alert("删除成功!");
						location.reload();
					}else{
						alert("删除失败!");
					}
				},"json"
			)
		}
	}
</script>
<body>
	<form action="list" method="post">
		
		<p class="h3 text-center" style="color: red">江苏人才库</p>
		<hr style="color: red">
		<input type="hidden" name="pageNum">
		<div class="input-group mb-3">
		  <div class="input-group-prepend">
		    <span class="input-group-text" id="basic-addon1">姓名</span>
		  </div>
			  <input type="text" placeholder="请输入姓名" name="taname" value="${talents.taname}">&nbsp;&nbsp;&nbsp;&nbsp;
		  <div class="input-group-prepend">
		    <span class="input-group-text" id="basic-addon1">职称</span>
		  </div>
			  <select name="tid">
			  	<option value="0">---请选择---</option>
			  	<c:forEach items="${title}" var="ite">
			  		<option value="${ite.tid}" ${ite.tid==talents.tid?"selected":""}>${ite.name}</option>
			  	</c:forEach>
			  </select>&nbsp;&nbsp;&nbsp;&nbsp;
			 <input type="submit" class="btn btn-danger" value="查询">  &nbsp;&nbsp;&nbsp;&nbsp;
			 <button type="button" class="btn btn-info" onclick="toAdd()">添加</button><br><br>
		</div>
		 快速查询: &nbsp;&nbsp;<a style="color: blue" onclick="query(0)">查询大于平均年龄的高级工程师</a> &nbsp;&nbsp;&nbsp;&nbsp;
		<a style="color: blue" onclick="query(1)">查询小于平均年龄的教授</a>
	</form>
		
		<table class="table">
		  <thead class="thead-dark">
		    <tr>
		      <th scope="col">序号</th>
		      <th scope="col">姓名</th>
		      <th scope="col">年龄</th>
		      <th scope="col">性别</th>
		      <th scope="col">联系电话</th>
		      <th scope="col">职称</th>
		      <th scope="col">擅长专业</th>
		      <th scope="col">所属单位</th>
		      <th scope="col">操作</th>
		    </tr>
		  </thead>
		  <tbody>
		  	<c:forEach items="${info.list}" var="in">
		  		<tr>
			      <th scope="row">${in.id}</th>
			      <td>${in.taname}</td>
			      <td>${in.age}</td>
			      <td>${in.gender.name}</td>
			      <td>${in.phone}</td>
			      <td>${in.titleName}</td>
			      <td>${in.specialty}</td>
			      <td>${in.institution}</td>
			      <td>
			      		<button type="button" class="btn btn-danger" onclick="update(${in.id})">修改</button>
			      		<button type="button" class="btn btn-info" onclick="del(${in.id})">删除</button>
			      </td>
			    </tr>
		  	</c:forEach>
		  	<thead>
			    <tr align="center" class="table-secondary">
			      <th colspan="111">
			      		当前${info.pageNum}/${info.pages}    共有条${info.total}数据
			      		<button type="button" class="btn btn-outline-primary" onclick="page(1)">首页</button>
					  	<button type="button" class="btn btn-outline-success" onclick="page(${info.prePage})">上一页</button>
					  	<button type="button" class="btn btn-outline-warning" onclick="page(${info.nextPage})">下一页</button>
					  	<button type="button" class="btn btn-outline-info" onclick="page(${info.pages})">尾页</button>
			      </th>
			    </tr>
			 </thead>
		</table>
</body>
</html>